<?php
/**
 * @introduction: 客服逻辑类
 * @author: 王龙
 */
namespace Common\Logic;

use Common\Model;

class CustomServiceLogic
{

    static public $model;

    public function __construct()
    {

        self::$model = new Model\CustomServiceModel();

    }

    /**
     * @introduction: 获取客服数据
     * @author: 王龙
     * @email: wanglong@cdlinglu.com
     * @param array or string $where 查询条件
     * @return array
     */
    static public function getData($where = '')
    {

        return self::$model
            ->where($where)
            ->select();

    }

    /**
     * @introduction: 添加客服
     * @author: 王龙
     * @email: wanglong@cdlinglu.com
     * @param array $data 添加的客服信息
     */
    static public function create($data = [])
    {

    	$result = self::$model
            ->add($data);

        if(!$result)
        	return ['code'=>300,'msg'=>'创建客服信息失败！'];

        return ['code'=>200,'msg'=>'创建客服信息成功！','data'=>$result]; 

    }

    /**
     * @introduction: 修改客服信息
     * @author: 王龙
     * @email: wanglong@cdlinglu.com
     * @param array $data 修改的客服信息
     * @param array $where 修改的地方
     */
    static public function save($where = array(),$data = array())
    {

    	$result = self::$model
    		->where($where)
            ->save($data);

        if(!$result)
        	return ['code'=>300,'msg'=>'修改客服信息失败！'];

        return ['code'=>200,'msg'=>'修改客服信息成功！','data'=>$result]; 
    }	

    /**
     * @introduction: 删除客服信息
     * @author: 王龙
     * @email: wanglong@cdlinglu.com
     * @param array $where 需要删除的地方
     */
    static public function delete($where = [])
    {

    	$result = self::$model
    		->where($where)
            ->delete();

        if(!$result)
        	return ['code'=>300,'msg'=>'删除客服信息失败！'];

       	return ['code'=>200,'msg'=>'删除客服信息成功！','data'=>$result]; 
    }

}